package com.example.testapplication;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

public class activityEvent extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event);
        findViewById(R.id.btn_main_test5).setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View view) {
                startActivity(new Intent(activityEvent.this,MotionEventTestActivity.class));

            }
        });

        findViewById(R.id.btn_main_test6).setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                startActivity(new Intent(activityEvent.this,KeyEventTestActivity.class));
                return true;
            }
        });
    }

    @Override
    public boolean onKeyUp(int keyCode, KeyEvent event) {
        // 监听back键
        if(event.getKeyCode() == KeyEvent.KEYCODE_BACK){
            // 显示确定的dialog
            new AlertDialog.Builder(this).setMessage("你确定退出吗？")
                    .setPositiveButton("退出", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            // 退出
                            finish();
                        }
                    })
                    .setNegativeButton("再看看",null)
                    .show();
            return true;
        }
        return super.onKeyUp(keyCode, event);
    }
}